//SPU请求
import request from "@/utils/request.ts";
import type {HasSpuResponseData,AllTradeMark,SaleAttrResponseData,HasSaleAttrResponseData,SpuData,SkuData} from './type.ts'
import {SkuInfoData, SpuHasImg} from "./type.ts";
enum API {
    HASSPU_URL='/admin/product/',//获取已有的SPU的数据
    ALLTRADERMARK_URL='/admin/product/baseTrademark/getTrademarkList',//获取全部品牌的数据
    IMAGE_URL='/admin/product/spuImageList/',//获取商品图片
    SPUHASSALEATTR_URL='/admin/product/spuSaleAttrList/',//获取销售数据
    ALLSALEATTR_URL='/admin/product/baseSaleAttrList',//整个项目全部的销售属性
    ADDSPU_URL='/admin/product/saveSpuInfo',//追加一个新的SPU
    UPDATESPU_URL='/admin/product/updateSpuInfo',//更新已有的SPU
    ADDSKU_URL='/admin/product/saveSkuInfo',//追加一个新增的SKU地址
    SKUINFO_URL='/admin/product/findBySpuId/',//查看某一个已有的SPU下全部售卖的商品
    REMOVESPU_URL='/admin/product/deleteSpu/',//删除已有的SPU
}
/**
 * 获取某一个三级分类下已有的SPU数据
 */
export const reqHasSPU = (page:number,limit:number,category3Id:number|string) => {
  return request.get<any,HasSpuResponseData>(API.HASSPU_URL+`${page}/${limit}?category3Id=${category3Id}`)
}
/**
 * 获取全部品牌的的请求
 */
export const reqAllTradeMark = () => {
  return request.get<any,AllTradeMark>(API.ALLTRADERMARK_URL)
}
/**
 * 获取品牌下的商品的图片地址
 * @param spuId
 */
export const reqSpuImageList = (spuId:number) => {
    return request.get<any,SpuHasImg>(API.IMAGE_URL+spuId)
}
/**
 * 获取已有的SPU拥有多少个销售属性
 * @param spuId
 */
export const reqSpuHasSaleAttr = (spuId:number) => {
    return request.get<any,SaleAttrResponseData>(API.SPUHASSALEATTR_URL+spuId)
}
/**
 * 获取全部的销售属性
 */
export const reqAllSaleAttr = () => {
    return request.get<any,HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
}
/**
 * 追加一个新的SPU
 * 更新已有的SPU
 * @param data 完整的SPU数据
 */
export const reqAddOrUpdateSpu = (data:SpuData) => {
  if(data.id){
      return request.post<any>(API.ADDSPU_URL,data)
  }else {
      return request.post<any>(API.UPDATESPU_URL,data)
  }
}
/**
 * 添加SKU的请求方法
 * @param data
 */
export const reqAddSku = (data:any) => {
  return request.post<any,SkuData>(API.ADDSKU_URL,data)
}
/**
 * 获取SKU数据
 */
export const reqSkuList = (spuId:number|string) => {
  return request.get<any,SkuInfoData>(API.SKUINFO_URL+spuId)
}
/**
 * 删除一个spu
 * @param spuId
 */
export const reqRemoveSpu = (spuId:number|string) => {
  return request.delete<any,any>(API.REMOVESPU_URL+spuId)
}